package cn.autoOffice.controller;

import cn.autoOffice.bean.pojo.Employee;
import cn.autoOffice.common.utils.MD5Utils;
import cn.autoOffice.common.utils.Result;
import cn.autoOffice.service.impl.LoginServiceImpl;
import cn.autoOffice.service.impl.RegisterServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class LoginAndRegistrationController {
@Autowired
public LoginServiceImpl loginService;
@Autowired
public RegisterServiceImpl registerService;

//登录验证
//     @RequestMapping("/login")
//     public Result login(@RequestParam("empCode")Integer empCode,
//                         @RequestParam("empPassword") String empPassword) {
//         empPassword = MD5Utils.MD5(empPassword);
//         Employee login = loginService.login(empCode, empPassword);
//         if (login==null) {
//             return Result.failure();
//         } else {
//             return Result.success(login);
//         }
//     }

//注册
    @PostMapping("/register")
    public Result register(Employee employee){
            employee.setEmpPassword(MD5Utils.MD5(employee.getEmpPassword()));
            int register = registerService.register(employee);
            if (register==1){
                return Result.success();
            }else {
                return Result.failure();
            }
    }

}
